//
//  RWDiskStore.h
//  XYYCache_Example
//
//  Created by ioszhb on 2020/8/13.
//  Copyright © 2020 developzhb. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface RWDiskStore : NSObject


@property (nonatomic, copy, readonly) NSString *name;
@property (nonatomic, copy, readonly) NSString *path;


/// 根据给定的name, 构建实例
/// @param name 不能为空,负责返回nil,
- (nullable instancetype)initWithName:(NSString *)name;
- (nullable instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER;
+ (nullable instancetype)diskStoreWithName:(NSString *)name;
+ (nullable instancetype)diskStoreWithPath:(NSString *)path;
- (instancetype)init UNAVAILABLE_ATTRIBUTE;
+ (instancetype)new UNAVAILABLE_ATTRIBUTE;
//默认name为@"COM.RWDiskStore"
+ (instancetype)defaultManager;

- (BOOL)containsObjectForKey:(NSString *)key;

- (void)setObject:(nullable id<NSSecureCoding>)object forKey:(NSString *)key;

- (nullable id<NSSecureCoding>)objectForKey:(NSString *)key forClass:(Class)classType;

- (void)updateObject:(nullable id<NSSecureCoding>)object forKey:(NSString *)key;

- (void)removeObjectForKey:(NSString *)key;

- (void)removeAllObjects;

+ (void)removeObjectsAtPath:(NSString *)path;

+ (void)removeObjectsWithName:(NSString *)name;

/// 根据key获取文件路径(warning: 只有key值对应的文件保存成功且在内存中,才有返回值.否则return nil)
/// @param key 查找文件的键
- (NSString *)readFilePathForKey:(NSString *)key;


/// 根据key获取文件的二进制数据(warning: 只有key值对应的文件保存成功且在内存中,才有返回值.否则return nil)
/// @param key 查找文件的键
- (NSData *)readDataForKey:(NSString *)key;

@end

NS_ASSUME_NONNULL_END
